//index.js
//获取应用实例
const app = getApp()
let Axios = require('../../../common/js/ajax.js');
let Mtils = require('../../../common/js/Mtils.min.js');
let util = require('../../../common/utils/util.js'); //转换时间插件
let webim = require('../../../common/utils/webim_wx.js'); //腾讯云im包
let webimhandler = require('../../../common/utils/webim_handler.js'); //这个是所有事件的腾讯js，这个页面需要用到登录
Mtils = Mtils.Mtils
var page = 1;
var switch_p = true
Page({
	data: {
		openid: '',
		nickName: '',
		avatarUrl: '',
		curentNav: 2, //当前导航
		menu: 0,
		cur_menu: 0,
		list: [],
		noData: '/img/noData.png', //无数据的图片
		contactList: [],
		delBtnWidth: 80,
		startX: "",
		numChat: 0,
		numNotice: 0,
		isIpx: app.globalData.isIpx ? true : false
	},
	//事件处理函数
	onLoad: function() {
		var _this = this;
		this.load = this.selectComponent("#loading");
		_this.load.loadIng()
		this.uid = app.globalData.uid || ''
		this.Md5 = Mtils.security.hex_md5(this.uid) + app.globalData.secret;
		this.Md5 = Mtils.security.hex_md5(this.Md5);
		this.timesp = Mtils.now();
		Axios.get(app.globalData.baseUrl + 'App/Message/Message/get_order_notice', {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				_this.setData({
					list: data
				})
				_this.load.loadIng()
			} else {
				_this.showModal(res)
			}
		})
		if (app.globalData.nickName && app.globalData.avatarUrl) {
			this.setData({
				nickName: app.globalData.nickName,
				avatarUrl: app.globalData.avatarUrl
			})
		}
	},
	onReady: function() {
		wx.setNavigationBarTitle({
			title: '订单通知'
		})
	},
	showModal: function(error) {
		wx.showModal({
			content: error.msg,
			showCancel: false,
		})
	},
	onReachBottom: function() {
		var _this = this;
		wx.showLoading({
			title: '玩命加载中',
			mask: true
		})
		switch_p = false
		page = page + 1;
		Axios.get(app.globalData.baseUrl + 'App/Message/Message/get_order_notice?p=' + page, {
			uid: this.uid,
			time: this.timesp,
			sign: this.Md5,
		}, (res) => {
			console.log(res)
			if (res.status == 1) {
				var data = res.info
				var temp = _this.data.list.concat(data)
				_this.setData({
					list: temp
				})
				switch_p = true
				wx.hideLoading();
			} else {
				_this.showModal(res)
			}
		})

	}
})
